var gulp = require("gulp"),//导入gulp插件
webserver = require("gulp-webserver"),//导入gulp-webserver静态服务器插件
livereload = require("gulp-livereload"),
sass = require("gulp-ruby-sass"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
tinypng=require("gulp-tinypng");

gulp.task("webserver",function(){
	gulp.src("dest")
	.pipe(webserver({
		livereload:true,
		open:"car.html",port:8888
	}))
})
//2.把html文件从开发环境发布到发布环境
gulp.task("html",function(){
	return gulp.src("src/**/*.html")
	.pipe(gulp.dest("dest"))
})

//4 sass
gulp.task("sass",function(){
	return sass("src/sass/*.scss",{style:"compressed"})
	.on("error",function(err){
		console.log(error);
	})
	.pipe(gulp.dest("dest/css"))
})
//5.js文件压缩&重命名
gulp.task("js",function(){
	return gulp.src("src/js/**/*.js")
	// .pipe(uglify())
	// .pipe(rename({suffix:".min"}))
	.pipe(gulp.dest("dest/js"));
})

//6.图片
gulp.task("tinypng",function(){
	return gulp.src("src/img/**/*.{png,jpg,gif,svg}")
	.pipe(gulp.dest("dest/images"))
})

//3.监听
gulp.task("watch",function(){
	gulp.watch("src/**/*.html",["html"]);
	gulp.watch("src/sass/*.scss",["sass"]);
	gulp.watch("src/js/**/*.js",["js"]);
	gulp.watch("src/img/*.{png,jpg,gif,svg}",["img"])
})

gulp.task("css",function(){
	return gulp.src("src/sass/**/*.css")
	.pipe(gulp.dest("dest/css"))
})

gulp.task("default",["webserver","html","sass","js","tinypng","watch","css"]);